﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Library.BLL;
using System.Drawing.Printing;

namespace View
{
    public partial class frmValores : Form
    {
        public frmValores()
        {
            InitializeComponent();
        }

        private void frmValores_Load(object sender, EventArgs e)
        {
            carregarDados();
        }   
        private void carregarDados()
        {
            ConfiguracoesController valores = new ConfiguracoesController();
            DataTable dtValores =  valores.getAllRecords();
            double ufesp = Double.Parse(dtValores.Rows[0]["UFESP"].ToString());
            double diariaUni =Double.Parse(dtValores.Rows[0]["DUNI"].ToString());
            double diariaTec = Double.Parse(dtValores.Rows[0]["DTEC"].ToString());
            this.txtUfesp.Text = ufesp.ToString("###.00");
            this.txtUni.Text = diariaUni.ToString("###.00");
            this.txtVlrDiariaUni.Text = diariaUni.ToString("###.00");
            this.txtTec.Text = diariaTec.ToString();



    //Universitario
            //pernoite sem alojamento
            this.txtTp1SAlojUni.Text = (ufesp * diariaUni * 2).ToString("###.00000");
            this.txtTp2SAlojUni.Text = (ufesp * diariaUni * 1.8).ToString("###.00000");
            this.txtTp3SAlojUni.Text = (ufesp * diariaUni * 1.7).ToString("###.00000");
            this.txtTp4SAlojUni.Text = (ufesp * diariaUni * 1.5).ToString("###.00000");
            this.txtTp5SAlojUni.Text = (ufesp * diariaUni ).ToString("###.00000");

            this.txtTp1SAlojUniArr.Text = (ufesp * diariaUni * 2).ToString("###.00");
            this.txtTp2SAlojUniArr.Text = (ufesp * diariaUni * 1.8).ToString("###.00");
            this.txtTp3SAlojUniArr.Text = (ufesp * diariaUni * 1.7).ToString("###.00");
            this.txtTp4SAlojUniArr.Text = (ufesp * diariaUni * 1.5).ToString("###.00");
            this.txtTp5SAlojUniArr.Text = (ufesp * diariaUni).ToString("###.00");


            //Pernoite com alojamento
            this.txtTp1CAlojUni.Text = (ufesp * diariaUni).ToString("###.00000");
            this.txtTp2CAlojUni.Text = ((ufesp * diariaUni * 1.8)/2).ToString("###.00000");
            this.txtTp3CAlojUni.Text = ((ufesp * diariaUni * 1.7/2)).ToString("###.00000");
            this.txtTp4CAlojUni.Text = ((ufesp * diariaUni * 1.5/2)).ToString("###.00000");
            this.txtTp5CAlojUni.Text = ((ufesp * diariaUni / 2)).ToString("###.00000");
            
            this.txtTp1CAlojUniArr.Text = (ufesp * diariaUni * 2).ToString("###.00");
            this.txtTp2CAlojUniArr.Text = (ufesp * diariaUni * 1.8).ToString("###.00");
            this.txtTp3CAlojUniArr.Text = (ufesp * diariaUni * 1.7).ToString("###.00");
            this.txtTp4CAlojUniArr.Text = (ufesp * diariaUni * 1.5).ToString("###.00");
            this.txtTp5CAlojUniArr.Text = (ufesp * diariaUni).ToString("###.00");

            //Deslocamento 6 horas
            this.txtTp16Uni.Text = ("0.00");
            this.txtTp26Uni.Text = ("0.00");
            this.txtTp36Uni.Text = ("0.00");
            this.txtTp46Uni.Text = ("0.00");
            this.txtTp56Uni.Text = ("0.00");

            this.txtTp16UniArr.Text = ("0.00");
            this.txtTp26UniArr.Text = ("0.00");
            this.txtTp36UniArr.Text = ("0.00");
            this.txtTp46UniArr.Text = ("0.00");
            this.txtTp56UniArr.Text = ("0.00");

            //Deslocamento 6-12 horas
            this.txtTp1612Uni.Text = (ufesp * diariaUni * 2 * 0.2).ToString("###.00000");
            this.txtTp2612Uni.Text = (ufesp * diariaUni * 1.8 * 0.2).ToString("###.00000");
            this.txtTp3612Uni.Text = (ufesp * diariaUni * 1.7 * 0.2).ToString("###.00000");
            this.txtTp4612Uni.Text = (ufesp * diariaUni * 1.5 * 0.2).ToString("###.00000");
            this.txtTp5612Uni.Text = (ufesp * diariaUni  * 0.2).ToString("###.00000");

            this.txtTp1612UniArr.Text = (ufesp * diariaUni * 2 * 0.2).ToString("###.00");
            this.txtTp2612UniArr.Text = (ufesp * diariaUni * 1.8 * 0.2).ToString("###.00");
            this.txtTp3612UniArr.Text = (ufesp * diariaUni * 1.7 * 0.2).ToString("###.00");
            this.txtTp4612UniArr.Text = (ufesp * diariaUni * 1.5 * 0.2).ToString("###.00");
            this.txtTp5612UniArr.Text = (ufesp * diariaUni * 0.2).ToString("###.00");

            //Deslocamento maior que 12 horas
            this.txtTp112Uni.Text = (ufesp * diariaUni * 2 * 0.4).ToString("###.00000");
            this.txtTp212Uni.Text = (ufesp * diariaUni * 1.8 * 0.4).ToString("###.00000");
            this.txtTp312Uni.Text = (ufesp * diariaUni * 1.7 * 0.4).ToString("###.00000");
            this.txtTp412Uni.Text = (ufesp * diariaUni * 1.5 * 0.4).ToString("###.00000");
            this.txtTp512Uni.Text = (ufesp * diariaUni * 0.4).ToString("###.00000");

            this.txtTp112UniArr.Text = (ufesp * diariaUni * 2 * 0.4).ToString("###.00");
            this.txtTp212UniArr.Text = (ufesp * diariaUni * 1.8 * 0.4).ToString("###.00");
            this.txtTp312UniArr.Text = (ufesp * diariaUni * 1.7 * 0.4).ToString("###.00");
            this.txtTp412UniArr.Text = (ufesp * diariaUni * 1.5 * 0.4).ToString("###.00");
            this.txtTp512UniArr.Text = (ufesp * diariaUni * 0.4).ToString("###.00");

    //Tecnico
            //pernoite sem alojamento
            this.txtTp1SAlojTec.Text = (ufesp * diariaTec * 2).ToString("###.00000");
            this.txtTp2SAlojTec.Text = (ufesp * diariaTec * 1.8).ToString("###.00000");
            this.txtTp3SAlojTec.Text = (ufesp * diariaTec * 1.7).ToString("###.00000");
            this.txtTp4SAlojTec.Text = (ufesp * diariaTec * 1.5).ToString("###.00000");
            this.txtTp5SAlojTec.Text = (ufesp * diariaTec).ToString("###.00000");

            this.txtTp1SAlojTecArr.Text = (ufesp * diariaTec * 2).ToString("###.00");
            this.txtTp2SAlojTecArr.Text = (ufesp * diariaTec * 1.8).ToString("###.00");
            this.txtTp3SAlojTecArr.Text = (ufesp * diariaTec * 1.7).ToString("###.00");
            this.txtTp4SAlojTecArr.Text = (ufesp * diariaTec * 1.5).ToString("###.00");
            this.txtTp5SAlojTecArr.Text = (ufesp * diariaTec).ToString("###.00");


            //Pernoite com alojamento
            this.txtTp1CAlojTec.Text = (ufesp * diariaTec).ToString("###.00000");
            this.txtTp2CAlojTec.Text = ((ufesp * diariaTec * 1.8) / 2).ToString("###.00000");
            this.txtTp3CAlojTec.Text = ((ufesp * diariaTec * 1.7 / 2)).ToString("###.00000");
            this.txtTp4CAlojTec.Text = ((ufesp * diariaTec * 1.5 / 2)).ToString("###.00000");
            this.txtTp5CAlojTec.Text = ((ufesp * diariaTec / 2)).ToString("###.00000");

            this.txtTp1CAlojTecArr.Text = (ufesp * diariaTec * 2).ToString("###.00");
            this.txtTp2CAlojTecArr.Text = (ufesp * diariaTec * 1.8).ToString("###.00");
            this.txtTp3CAlojTecArr.Text = (ufesp * diariaTec * 1.7).ToString("###.00");
            this.txtTp4CAlojTecArr.Text = (ufesp * diariaTec * 1.5).ToString("###.00");
            this.txtTp5CAlojTecArr.Text = (ufesp * diariaTec).ToString("###.00");

            //Deslocamento 6 horas
            this.txtTp16Tec.Text = ("0.00");
            this.txtTp26Tec.Text = ("0.00");
            this.txtTp36Tec.Text = ("0.00");
            this.txtTp46Tec.Text = ("0.00");
            this.txtTp56Tec.Text = ("0.00");

            this.txtTp16TecArr.Text = ("0.00");
            this.txtTp26TecArr.Text = ("0.00");
            this.txtTp36TecArr.Text = ("0.00");
            this.txtTp46TecArr.Text = ("0.00");
            this.txtTp56TecArr.Text = ("0.00");


            //Deslocamento 6-12 horas
            this.txtTp1612Tec.Text = (ufesp * diariaTec * 2 * 0.2).ToString("###.00000");
            this.txtTp2612Tec.Text = (ufesp * diariaTec * 1.8 * 0.2).ToString("###.00000");
            this.txtTp3612Tec.Text = (ufesp * diariaTec * 1.7 * 0.2).ToString("###.00000");
            this.txtTp4612Tec.Text = (ufesp * diariaTec * 1.5 * 0.2).ToString("###.00000");
            this.txtTp5612Tec.Text = (ufesp * diariaTec * 0.2).ToString("###.00000");

            this.txtTp1612TecArr.Text = (ufesp * diariaTec * 2 * 0.2).ToString("###.00");
            this.txtTp2612TecArr.Text = (ufesp * diariaTec * 1.8 * 0.2).ToString("###.00");
            this.txtTp3612TecArr.Text = (ufesp * diariaTec * 1.7 * 0.2).ToString("###.00");
            this.txtTp4612TecArr.Text = (ufesp * diariaTec * 1.5 * 0.2).ToString("###.00");
            this.txtTp5612TecArr.Text = (ufesp * diariaTec * 0.2).ToString("###.00");

            //Deslocamento maior que 12 horas
            this.txtTp112Tec.Text = (ufesp * diariaTec * 2 * 0.4).ToString("###.00000");
            this.txtTp212Tec.Text = (ufesp * diariaTec * 1.8 * 0.4).ToString("###.00000");
            this.txtTp312Tec.Text = (ufesp * diariaTec * 1.7 * 0.4).ToString("###.00000");
            this.txtTp412Tec.Text = (ufesp * diariaTec * 1.5 * 0.4).ToString("###.00000");
            this.txtTp512Tec.Text = (ufesp * diariaTec * 0.4).ToString("###.00000");

            this.txtTp112TecArr.Text = (ufesp * diariaTec * 2 * 0.4).ToString("###.00");
            this.txtTp212TecArr.Text = (ufesp * diariaTec * 1.8 * 0.4).ToString("###.00");
            this.txtTp312TecArr.Text = (ufesp * diariaTec * 1.7 * 0.4).ToString("###.00");
            this.txtTp412TecArr.Text = (ufesp * diariaTec * 1.5 * 0.4).ToString("###.00");
            this.txtTp512TecArr.Text = (ufesp * diariaTec * 0.4).ToString("###.00");

        }

        private void label17_Click(object sender, EventArgs e)
        {

        }

        private void btnImprimir_Click(object sender, EventArgs e)
        {

            /*
            PrintDocument documentoValores = new PrintDocument();

            documentoValores.

            
   
                On Error GoTo MEUERROP
                Printer.PaperSize = 9
                Printer.Orientation = 1
                Printer.FontName = "courier new"
                Printer.FontSize = 11
                Printer.Print
                Printer.Print
                Printer.FontBold = True
                Printer.FontUnderline = True
                Printer.Print Tab(4); "Relação de Valores de Diária"
                Printer.FontBold = False
                Printer.FontUnderline = False
                Printer.FontSize = 11
                Printer.Print
                Printer.Print Tab(4); "impresso em " & Format(Now, "dd/mmmm/yyyy") & " - Valor da UFESP: " & cufesp.Caption
                Printer.Print
                Printer.FontBold = True
                Printer.FontUnderline = True
                Printer.Print Tab(4); "Nível Universitário - " & cdu.Caption & " UFESPS - VALOR DE REFERÊNCIA: " & dua.Caption
                Printer.FontBold = False
                Printer.FontUnderline = False
                Printer.Print
                Printer.Print Tab(4); "FATOR LOCAL                       PERNOITE                  RETORNO/DESLOCAMENTO"
                Printer.Print Tab(4); "                      COM ALOJAMENTO  SEM ALOJAMENTO     TIPO A 20%      TIPO B 40%"
                Printer.Print Tab(4); "TIPO 1 - 100%"; Tab(30); Format(upc1a.Caption, "@@@@@@"); Tab(46); Format(ups1a.Caption, "@@@@@@"); Tab(62); Format(ura1a.Caption, "@@@@@@"); Tab(78); Format(urb1a.Caption, "@@@@@@")
                Printer.Print Tab(4); "TIPO 2 -  80%"; Tab(30); Format(upc2a.Caption, "@@@@@@"); Tab(46); Format(ups2a.Caption, "@@@@@@"); Tab(62); Format(ura2a.Caption, "@@@@@@"); Tab(78); Format(urb2a.Caption, "@@@@@@")
                Printer.Print Tab(4); "TIPO 3 -  70%"; Tab(30); Format(upc3a.Caption, "@@@@@@"); Tab(46); Format(ups3a.Caption, "@@@@@@"); Tab(62); Format(ura3a.Caption, "@@@@@@"); Tab(78); Format(urb3a.Caption, "@@@@@@")
                Printer.Print Tab(4); "TIPO 4 -  50%"; Tab(30); Format(upc4a.Caption, "@@@@@@"); Tab(46); Format(ups4a.Caption, "@@@@@@"); Tab(62); Format(ura4a.Caption, "@@@@@@"); Tab(78); Format(urb4a.Caption, "@@@@@@")
                Printer.Print Tab(4); "TIPO 5 -   0%"; Tab(30); Format(upc5a.Caption, "@@@@@@"); Tab(46); Format(ups5a.Caption, "@@@@@@"); Tab(62); Format(ura5a.Caption, "@@@@@@"); Tab(78); Format(urb5a.Caption, "@@@@@@")
                Printer.Print
                Printer.Print
                Printer.FontBold = True
                Printer.FontUnderline = True
                Printer.Print Tab(4); "Nível Técnico - " & cdt.Caption & " UFESPS - VALOR DE REFERÊNCIA: " & dta.Caption
                Printer.FontBold = False
                Printer.FontUnderline = False
                Printer.Print
                Printer.Print Tab(4); "FATOR LOCAL                       PERNOITE                  RETORNO/DESLOCAMENTO"
                Printer.Print Tab(4); "                      COM ALOJAMENTO  SEM ALOJAMENTO     TIPO A 20%      TIPO B 40%"
                Printer.Print Tab(4); "TIPO 1 - 100%"; Tab(30); Format(tpc1a.Caption, "@@@@@@"); Tab(46); Format(tps1a.Caption, "@@@@@@"); Tab(62); Format(tra1a.Caption, "@@@@@@"); Tab(78); Format(trb1a.Caption, "@@@@@@")
                Printer.Print Tab(4); "TIPO 2 -  80%"; Tab(30); Format(tpc2a.Caption, "@@@@@@"); Tab(46); Format(tps2a.Caption, "@@@@@@"); Tab(62); Format(tra2a.Caption, "@@@@@@"); Tab(78); Format(trb2a.Caption, "@@@@@@")
                Printer.Print Tab(4); "TIPO 3 -  70%"; Tab(30); Format(tpc3a.Caption, "@@@@@@"); Tab(46); Format(tps3a.Caption, "@@@@@@"); Tab(62); Format(tra3a.Caption, "@@@@@@"); Tab(78); Format(trb3a.Caption, "@@@@@@")
                Printer.Print Tab(4); "TIPO 4 -  50%"; Tab(30); Format(tpc4a.Caption, "@@@@@@"); Tab(46); Format(tps4a.Caption, "@@@@@@"); Tab(62); Format(tra4a.Caption, "@@@@@@"); Tab(78); Format(trb4a.Caption, "@@@@@@")
                Printer.Print Tab(4); "TIPO 5 -   0%"; Tab(30); Format(tpc5a.Caption, "@@@@@@"); Tab(46); Format(tps5a.Caption, "@@@@@@"); Tab(62); Format(tra5a.Caption, "@@@@@@"); Tab(78); Format(trb5a.Caption, "@@@@@@")
                Printer.Print
                Printer.Print
                Printer.FontBold = True
                Printer.FontUnderline = True
                Printer.Print Tab(4); "Observações"
                Printer.FontBold = False
                Printer.FontUnderline = False
                Printer.FontSize = 10
                Printer.Print
                Printer.Print Tab(4); "TIPO 1 - DF e Manaus"
                Printer.Print Tab(4); "TIPO 2 - São Paulo, Rio de Janeiro, Recife, Belo Horizonte, Porto Alegre,"
                Printer.Print Tab(4); "         Belém , Fortaleza, Salvador"
                Printer.Print Tab(4); "TIPO 3 - demais capitais"
                Printer.Print Tab(4); "TIPO 4 - população >= 200.000 distantes pelo menos 70 kms da sede"
                Printer.Print Tab(4); "TIPO 5 - demais municípios"
                Printer.Print
                Printer.Print Tab(4); "TIPOA A - Retorno entre 13:00 e 19:00 e Deslocamentos de 6 a 12 horas"
                Printer.Print Tab(4); "TIPOA B - Retorno após as 19:00 e Deslocamentos maiores ou iguais a 12 horas"
                Printer.Print
                Printer.Print
                Printer.FontSize = 11
                Printer.FontBold = True
                Printer.FontUnderline = True
                Printer.Print Tab(4); "Municípios de SP atualmente configurados como 'TIPO 4'"
                Printer.FontSize = 10
                Printer.FontBold = False
                Printer.FontUnderline = False
                Form1.enche.RecordSource = "select * from tab_local where ufloc='SP' and tipo=4 order by nomeloc"
                Form1.enche.Refresh
                If Form1.enche.Recordset.BOF = True Then
                    Printer.Print
                    Printer.Print Tab(4); "Verifique sua configuração de 'Tipos de Municípios'"
                    Printer.Print Tab(4); "Não constam municípios configurados como 'TIPO 4'!!!"
                Else
                    Printer.Print
                    Form1.enche.Recordset.MoveFirst
                    minhatab = 1
                    Do While Not Form1.enche.Recordset.EOF
                        If minhatab = 3 Then
                            Printer.Print Tab(70); Form1.enche.Recordset("nomeloc")
                            minhatab = 1
                        ElseIf minhatab = 2 Then
                            Printer.Print Tab(37); Form1.enche.Recordset("nomeloc");
                            minhatab = 3
                        ElseIf minhatab = 1 Then
                            Printer.Print Tab(4); Form1.enche.Recordset("nomeloc");
                            minhatab = 2
                        End If
                        Form1.enche.Recordset.MoveNext
                    Loop
                    Printer.Print
                    Printer.Print
                    Printer.Print Tab(4); "Sempre verifique sua configuração de 'Tipos de Municípios'"
                    Printer.Print Tab(4); Form1.enche.Recordset.RecordCount & " municípios configurados como 'TIPO 4'."
                End If
                Printer.EndDoc
                MsgBox "Dados impressos com sucesso", 64

                Exit Sub
                MEUERROP:
                Err = 0
                Resume Next
             * 
             * 
             * */


            PrintDialog printWindow = new PrintDialog();
            printWindow.ShowDialog();
        }

        private void groupBox8_Enter(object sender, EventArgs e)
        {

        }
    }
}
